<?php
/**
*
* @package phpBB3
* @version $Id$
* @copyright (c) 2010
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/	
    	
/*
*	This service will:
*	1. If it's in trading time, check all delegations and get related stock price/volume 
*		to see if the delegations can be done.
*	2. If it's not in trading time, get stock price/volume for all corp for each trading day. 
* 
*	Note: this file should be in ASCII format!
*/	
 
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include_once($phpbb_root_path . 'common.' . $phpEx);
include_once($phpbb_root_path . 'sv_common.' . $phpEx);
// We include config.php here to include the dbpassword again, as some tasks, like fill_corp_info, take much longer time than expected and we may need to re-connect SQL server.
include_once($phpbb_root_path . 'config.' . $phpEx);

// allow the service to run up to 2 hour as it may take long time to grab data from TWSE and OTC.
if (!get_cfg_var('safe_mode')) 
{
	set_time_limit(7200);	
} 

// check the service lock.
$a = new service_lock(basename(__FILE__));
if ($a->lock() == false)
{
	// another instance is running.
	echo "\n\nanother instance is running.\n";
	echo date('Y/m/d H:i:s', get_taiwan_time()) . PHP_EOL . PHP_EOL;
	die;	
}

// get taiwan time.		
$time = get_taiwan_time();

// print service log.
print_service_log(__FILE__, $time);
		

// get news related to hot companies.
begin_service_task('get_news');
get_news();
end_service_task('get_news');
	

// print service log end.
print_service_log_end();
?>